package com.plant.agent.comtroller;

import com.plant.agent.domain.Agent;
import com.plant.agent.mapper.AgentMapper;
import com.plant.agent.service.AgentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/agent")
@Slf4j
public class AgentController {

    @Autowired
    private AgentService agentService;

    @RequestMapping("/findAgent")
    public List<Agent> findAgent() {
        return agentService.findAgent();
    }
    @GetMapping("/findAgent2")
    public Agent findAgent2(@RequestParam("did") Integer did) {
        return agentService.findAgent2(did);
    }
    @PostMapping("/addAgent")
    public boolean addAgent(@RequestBody Agent agent) {
        return agentService.addAgent(agent);
    }
    @GetMapping("/findAll")
    public Agent findAll(@RequestParam("did") Integer did){
     return agentService.findAll(did);
    }
    @GetMapping("/updatestatus3")
    public int updatestatus3(@RequestParam("did") Integer did){
        return agentService.updatestatus3(did);
    }
    @GetMapping("/updatestatus4")
    public int updatestatus4(@RequestParam("did") Integer did){
        return agentService.updatestatus4(did);
    }
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private AgentMapper agentMapper;

    @GetMapping("/findDname")
    public Agent findDname(){
        String string = redisTemplate.opsForValue().get("agent").toString();
        log.info("redis获取数据："+string);
        return agentMapper.findDname(string);
    }
    @GetMapping("/findDname2")
    public int findDname2(@RequestParam("dname") String dname){
        Agent dname1 = agentMapper.findDname(dname);
        if (dname1!=null){
            return 1;
        }else {
            return 0;
        }
    }
}
